package com.example.springcloudfeign.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.springcloudfeign.feign.TestFeign;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author X.I.O
 * @title: TestController
 * @projectName spring-cloud-1
 * @description: TODO
 * @date 2021/11/7 13:26
 */
@RestController
@RequestMapping("/feign/test")
@ApiModel("feign测试模块")
public class TestController {

    @Autowired
    private TestFeign testFeign;

    @ApiOperation("测试模块")
    @RequestMapping(value = "/hello", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public JSONObject postPerson(String name) {
        String str=testFeign.hello();
        JSONObject obj=new JSONObject();
        obj.put("msg",str);
        return obj;
    }

    @ApiOperation("测试模块2")
    @GetMapping("/test-demo2")
    public JSONObject testJSONObjectController(@ApiParam("账号") @RequestParam("username")String username,
                                               @ApiParam("密码")@RequestParam("password")String password){
        Map<String, Object> map=new HashMap<>();
        map.put("username",username);
        map.put("password",password);
        JSONObject object=testFeign.getJSONObject(map);
        return object;
    }
}
